<?php
/*
    功能：图片桥接镜像程序
    
    php 程序访问的图片是绝对路径，但 img 访问的是网络路径
    或网站根目录以下的相对路径，此程序的目的是把图片的绝
    对路径转成程序文件同目录下的相对路径，便于 img 访问。
*/

$imgurl = urldecode($_GET['url']);
$extention = strtolower(pathinfo($imgurl, PATHINFO_EXTENSION));

function LoadImg($imgname = '', $extention = 'jpg')
{
    switch($extention){
        case 'jpg':
        case 'jpeg':
            $im = imagecreatefromjpeg($imgname);
            break;
        case 'png':
            $im = imagecreatefrompng($imgname);
            break;
        case 'gif':
            $im = imagecreatefromgif($imgname);
            break;
        case 'bmp':
            $im = imagecreatefrombmp($imgname);
            break;
        case 'wbmp':
            $im = imagecreatefromwbmp($imgname);
            break;
        case 'webp':
            $im = imagecreatefromwebp($imgname);
            break;
        case 'xbm':
            $im = imagecreatefromxbm($imgname);
            break;
        case 'xpm':
            $im = imagecreatefromxpm($imgname);
            break;
    }
    
    if(!$im){
        $im  = imagecreatetruecolor(200, 50);
        $bgc = imagecolorallocate($im, 240, 250, 250);
        $tc  = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 200, 50, $bgc);
        
        imagestring($im, 5, 5, 16, 'Error loading picture!', $tc);
    }
    return $im;
}

header('Content-Type: image/jpeg');
$img = LoadImg($imgurl, $extention);
imagejpeg($img);
imagedestroy($img);